package com.yc.litemonitoring.client;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;


public class LiteMonitoringClientInitializer extends
        ChannelInitializer<Channel> {

    private final static int MAX_OBJECT_SIZE = 1024 * 1024;

    @Override
    protected void initChannel(Channel ch) throws Exception {
        // 初始化pipeline, 并添加handler, 最后添加业务handler
        ChannelPipeline pipeline = ch.pipeline();

        // 加入解码器和编码器
        pipeline.addLast(new ObjectDecoder(MAX_OBJECT_SIZE,
                ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));

        pipeline.addLast(new ObjectEncoder());


        pipeline.addLast(new LiteMonitoringClientHandler());
    }
}
